package com.zhz.employee.biz;

import com.zhz.common.utils.ConvertUtils;
import com.zhz.employee.contract.request.EmployeeFindPositiveRequest;
import com.zhz.employee.contract.request.EmployeePositiveSaveRequest;
import com.zhz.employee.repository.service.EmployeePositiveService;
import com.zhz.model.employee.contract.dto.EmployeePositiveDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 转正申请业务service
 *
 * @author zhouhengzhe
 * @date 2023/5/30
 */
@Component
public class EmployeePositiveBizService {

    private final EmployeePositiveService employeePositiveService;

    @Autowired
    public EmployeePositiveBizService(EmployeePositiveService employeePositiveService) {
        this.employeePositiveService = employeePositiveService;
    }

    /**
     * 转正表单保存
     *
     * @param employeePositiveSaveRequest 转正表单保存请求
     */
    public void save(EmployeePositiveSaveRequest employeePositiveSaveRequest) {
        EmployeePositiveDTO employeePositiveDTO = ConvertUtils.sourceToTarget(employeePositiveSaveRequest, EmployeePositiveDTO.class);
        employeePositiveService.save(employeePositiveDTO);
    }

    /**
     * 转正表单读取
     *
     * @param employeeFindPositiveRequest 转正表单读取请求
     * @return 转正表单读取响应
     */
    public EmployeePositiveDTO findPositive(EmployeeFindPositiveRequest employeeFindPositiveRequest) {
        EmployeePositiveDTO employeePositiveDTO = employeePositiveService.get(employeeFindPositiveRequest.getId());
        if (Objects.isNull(employeePositiveDTO)) {
            employeePositiveDTO = EmployeePositiveDTO
                    .builder()
                    .userId(employeeFindPositiveRequest.getId())
                    .build();
        }
        return employeePositiveDTO;
    }
}
